from bs4 import BeautifulSoup

class HtmlJdIphoneId(object):
  def readIdsLs(this,htmlTxt):
    # 创建Beautiful Soup对象
    soup = BeautifulSoup(htmlTxt, 'html.parser')
    pList = soup.find(class_ = "p-list")
    if pList == None:
      return "没有数据"
    trs = pList.find_all("tr")
    index = 0
    uuTxt = ''
    for tr in trs:
      # if index == 0:
      #   print(tr)
      inpUname = tr.find(id = "game_cardNo")
      inpPwd = tr.find(id = "game_cardpwddecode")
      if inpUname != None:
        unameStr = inpUname.attrs['onclick']
        unameStr = unameStr.replace("copyToClipboard('","")
        unameStr = unameStr[0:len(unameStr) - 3]

        pwdStr = inpPwd.attrs['onclick']
        pwdStr = pwdStr.replace("copyToClipboard('","")
        pwdStr = pwdStr[0:len(pwdStr) - 3]
        index += 1
        if index != 1:
          uuTxt+='\n'
        uuTxt+=str(index) +'\t'+unameStr+'\t'+pwdStr
        # print(index, unameStr,pwdStr)
    # print(uuTxt)  
    return uuTxt
  def test(this):
    htmlTxt = ''
    with open("biz_log.txt", "r",encoding='utf-8') as f: 
      htmlTxt = f.read()  # 读取文件
    result = this.readIdsLs(htmlTxt)
    print(result)

# HtmlJdIphoneId().test()